class Person():
    name = ''

    def __init__(self, name):
        self.name = name

    def say(self):
        print('我是%s, 我会说话' % self.name)


class Dog():
    name = ''

    def __init__(self, name):
        self.name = name

    def say(self):
        print('wangwangwang')


# p = Person('zhangsan')
# p.say()
#
# p1 = Person('p1')
# p1.say()
# p2 = Person('p2')
# p2.say()
# p3 = Person('p3')
# p3.say()
# p4 = Person('p4')
# p4.say()

p_list = [Person('p1'), Person('p2'), Person('p3'), Person('p4'), Dog('xiaohang')]


def p_say(p_list):
    for p in p_list:
        say = getattr(p, 'say', None)  # p.say
        if say:
            say()
        else:
            print('这个叫%s的动物不会说话' % p.name)



p_say(p_list)
